cmp.ready(function () {
    _initBackEvent();

    cmp.i18n.init(_collPath + "/i18n/", "Collaboration", function () {
        _initLayout();
        _fillPage();
    });
});

function _initBackEvent() {

    cmp.backbutton();
    cmp.backbutton.push(_goBack);
    _$("#goBackBtn").addEventListener("tap", _goBack);
}

function _initLayout(){
    cmp.listView("#contentView", {});
}

// 页面布局
function _fillPage() {
    loadData();
}

//返回
function _goBack() {
    cmp.href.back();
}

function loadData() {
    var summaryBO = cmp.href.getParam("summaryBO")

    var params = {
        "summaryId": summaryBO.summary.id,
        "isHistoryFlag": "",
    };
    cmp.dialog.loading();
    $s.EdocResource.attachmentList({}, params, errorBuilder({
        success: function (result) {
            cmp.dialog.loading(false);
            var formalList = [];
            var exchangeList = [];
            //关联文档个数
            var formalAsscCount = 0;
            var exchangeAsscCount = 0;
            if (result && result.data && result.data.length > 0) {
                for (var i = 0; i < result.data.length; i++) {
                    var item = result.data[i];
                    if (item.from == 0 || item.from == 1) {
                        formalList.push(item);
                        if (item.type == "2" || item.type == "collaboration"
                            || item.type == "docFile" || item.type == "edoc") {
                            formalAsscCount++;
                        }
                    } else {
                        exchangeList.push(item);
                        if (item.type == "2" || item.type == "collaboration"
                            || item.type == "docFile" || item.type == "edoc") {
                            exchangeAsscCount++;
                        }
                    }
                }
            }
            CollUtils.initAttStyle("#attachments_formal", formalList);
            CollUtils.initAttStyle("#attachments_exchange", exchangeList);
            _$("#attachments_formal_title").innerText = cmp.i18n('collaboration.page.lable.formalAttachment', [formalList.length - formalAsscCount, formalAsscCount]);
            _$("#attachments_exchange_title").innerText = cmp.i18n('collaboration.page.lable.exchangeAttachment', [exchangeList.length - exchangeAsscCount, exchangeAsscCount]);
            _$("#attachments_formal_container").style.display = "block";
            _$("#attachments_exchange_container").style.display = "block";
        }
    }));

}

